package com.banmao.algorithm.No701To900.No844;

import java.util.Stack;

public class Solution1 {

    public static boolean backspaceCompare(String s, String t) {
        return buildStr(s).equals(buildStr(t));
    }

    public static String buildStr(String str) {
        Stack<Character> stack = new Stack<Character>();
        char[] strC = str.toCharArray();
        for (char c : strC) {
            if('#' == c) {
                if(!stack.isEmpty()) {
                    stack.pop();
                }
            } else {
                stack.add(c);
            }
        }
        return stack.toString();
    }

}
